columnview: Add a GtkColumnViewColumn:expand property
authorMatthias Clasen <mclasen@redhat.com>
Mon, 23 Dec 2019 04:10:01 +0000 (23:10 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 3 Jun 2020 17:32:15 +0000 (13:32 -0400)
This will be used to determine how to distribute
available extra space in a column view.

docs/reference/gtk/gtk4-sections.txt
gtk/gtkcolumnviewcolumn.c
gtk/gtkcolumnviewcolumn.h

index 20f83525928618d8536885c2257f586f0c33acfc..dc19164f0c68358ce09e882ad882f34967b2ba92 100644 (file)
@@ -541,6 +541,8 @@ gtk_column_view_column_set_header_menu
 gtk_column_view_column_get_header_menu
 gtk_column_view_column_set_fixed_width
 gtk_column_view_column_get_fixed_width
+gtk_column_view_column_set_expand
+gtk_column_view_column_get_expand
 
 <SUBSECTION Standard>
 GTK_COLUMN_VIEW_COLUMN
index 8879457a7f208b49bf0f8ac248300d9817dcdef6..056793190553bfe1be59e55247f91b5d74f0b0f4 100644 (file)
@@ -64,8 +64,9 @@ struct _GtkColumnViewColumn
 
   int fixed_width;
 
-  guint visible : 1;
-  guint resizable : 1;
+  guint visible     : 1;
+  guint resizable   : 1;
+  guint expand      : 1;
 
   GMenuModel *menu;
 
@@ -88,6 +89,7 @@ enum
   PROP_VISIBLE,
   PROP_HEADER_MENU,
   PROP_RESIZABLE,
+  PROP_EXPAND,
   PROP_FIXED_WIDTH,
 
   N_PROPS
@@ -151,6 +153,10 @@ gtk_column_view_column_get_property (GObject    *object,
       g_value_set_boolean (value, self->resizable);
       break;
 
+    case PROP_EXPAND:
+      g_value_set_boolean (value, self->expand);
+      break;
+
     case PROP_FIXED_WIDTH:
       g_value_set_int (value, self->fixed_width);
       break;
@@ -195,6 +201,10 @@ gtk_column_view_column_set_property (GObject      *object,
       gtk_column_view_column_set_resizable (self, g_value_get_boolean (value));
       break;
 
+    case PROP_EXPAND:
+      gtk_column_view_column_set_expand (self, g_value_get_boolean (value));
+      break;
+
     case PROP_FIXED_WIDTH:
       gtk_column_view_column_set_fixed_width (self, g_value_get_int (value));
       break;
@@ -298,6 +308,18 @@ gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
+  /**
+   * GtkColumnViewColumn:expand:
+   *
+   * Column gets share of extra width allocated to the view
+   */
+  properties[PROP_EXPAND] =
+    g_param_spec_boolean ("expand",
+                          P_("Expand"),
+                          P_("column gets share of extra width"),
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
   /**
    * GtkColumnViewColumn:fixed-width:
    *
@@ -321,6 +343,7 @@ gtk_column_view_column_init (GtkColumnViewColumn *self)
   self->natural_size_request = -1;
   self->visible = TRUE;
   self->resizable = FALSE;
+  self->expand = FALSE;
   self->fixed_width = -1;
 }
 
@@ -845,6 +868,49 @@ gtk_column_view_column_get_header_menu (GtkColumnViewColumn *self)
   return self->menu;
 }
 
+/**
+ * gtk_column_view_column_set_expand:
+ * @self: a #GtkColumnViewColumn
+ * @expand: %TRUE if this column should expand to fill available sace
+ *
+ * Sets the column to take available extra space.
+ *
+ * The extra space is shared equally amongst all columns that
+ * have the expand set to %TRUE.
+ */
+void
+gtk_column_view_column_set_expand (GtkColumnViewColumn *self,
+                                   gboolean             expand)
+{
+  g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self));
+
+  if (self->expand == expand)
+    return;
+
+  self->expand = expand;
+
+  if (self->visible && self->view)
+    gtk_widget_queue_resize (GTK_WIDGET (self->view));
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_EXPAND]);
+}
+
+/**
+ * gtk_column_view_get_expand:
+ * @self: a #GtkColumnViewColumn
+ *
+ * Returns whether this column should expand.
+ *
+ * Returns: %TRUE if this column expands
+ */
+gboolean
+gtk_column_view_column_get_expand (GtkColumnViewColumn *self)
+{
+  g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), TRUE);
+
+  return self->expand;
+}
+
 /**
  * gtk_column_view_column_set_resizable:
  * @self: a #GtkColumnViewColumn
index 459c4d372f0755b394282b630ec664625eb2b794..a0e9bd946c5d2179794797ca9acd252771814082 100644 (file)
@@ -96,6 +96,12 @@ void                    gtk_column_view_column_set_resizable            (GtkColu
 GDK_AVAILABLE_IN_ALL
 gboolean                gtk_column_view_column_get_resizable            (GtkColumnViewColumn    *self);
 
+GDK_AVAILABLE_IN_ALL
+void                    gtk_column_view_column_set_expand               (GtkColumnViewColumn    *self,
+                                                                         gboolean                expand);
+GDK_AVAILABLE_IN_ALL
+gboolean                gtk_column_view_column_get_expand            (GtkColumnViewColumn    *self);
+
 G_END_DECLS
 
 #endif  /* __GTK_COLUMN_VIEW_COLUMN_H__ */